import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.jueyunqi.producer.MessageProducer;


public class App {
	private static ApplicationContext factory = null;
	static {
		factory = new ClassPathXmlApplicationContext(
				"classpath:applicationContext.xml");
//		for (String item : factory.getBeanDefinitionNames()) {
//			System.out.println(item);
//		}
	}

	public static ApplicationContext getContext() {
		return factory;
	}
	
	public static void main(String[] args) {
		ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();  
		singleThreadExecutor.execute(new Runnable() {
			private int count = 0;
			
			@Override
			public void run() {
				while (count < 1000) {
					MessageProducer producer = getContext().getBean(MessageProducer.class);
					producer.sendMessage("thread index "+(count++));
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		});
		
		try {
			System.in.read();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
